<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class party_model extends CI_Model {

	private $table_name			= 'parties';			// user accounts
	
    function __construct() {
        parent::__construct();
        
        	$ci =& get_instance();
		$this->table_name			= $ci->config->item('db_table_prefix', 'party').$this->table_name;
    }

  /*  public function create_party($data) {
        $data = array('name_event' => $name_event,
            'content' => $content);
            'pic_menu' => $pic,
            'date_start' => $date_start,
            'date_end' => $date_end,
            'activate' => $activate);
        $this->db->insert('parties', $data);

        return $this->db->insert_id();
    } */
    
    function create_party($data)
	{

		if ($this->db->insert($this->table_name, $data)) {
			$party_id = $this->db->insert_id();
			return array('party_id' => $party_id);
		}
		return NULL;
	}


/*function process_pic()
    {   
        //Get File Data Info
        $uploads = array($this->upload->data());
        
        $this->load->library('image_lib');  
        
        
    }   */   
    

    public function get_party_by_id($id) {
        $this->db->where('id', (int)$id);
        $this->db->from('parties');

        $query = $this->db->get();

        if ($query->num_rows() > 0)
            return $query->row();

        return null;
    }
    
    function get_list_parties()
    {      
     
     $query = $this->db->query("Select * from parties");
    
     return $query->result();     
        
    }



/*function insert_pic($data)
    {
    
      if ($this->db->update($this->table_name, $data)) {
			$party_id = $this->db->insert_id();
			return array('party_id' => $party_id);
		}
		return NULL;
      
        //Get File Data Info
        $uploads = array($this->upload->data());
        $this->load->library('image_lib');

        //Move Files To Party Folder
        foreach($uploads as $key => $value)
        {

           $pictureField = $value['file_ext'];

            //Move Uploaded Files with name
            rename($value['full_path'],'/pictures/'.$pictureField);


            //Add Pic Info To Database
            $this->db->set('flyer_front', $pictureField);
            $this->db->set('flyer_back', $pictureField);
            $this->db->set('picture_menu', $pictureField);

            //Insert Info Into Database
            $this->db->update($this->table_name);

        }
    
    } */
    
 
function doUpload($data)
{

    $data = array('flyer_front' => $flyer_front,
            'flyer_back' => $flyer_back,
            'picture_menu' => $picture_menu);
    
    $this->db->update('parties', $data);

    return array('flyer_front' => $flyer_front,
                 'flyer_back' => $flyer_back,
                 'picture_menu' => $picture_menu); 

   var_dump($data);


   /* $this->db->set('flyer_front', $flyer_front);
		$this->db->set('flyer_back', $flyer_back);
		$this->db->set('picture_menu', $picture_menu);

    $this->db->where('id', $currentPartyId);
    
    $this->db->update($this->table_name);
    
    return array('flyer_front' => $flyer_front,
                 'flyer_back' => $flyer_back,
                 'picture_menu' => $picture_menu);  */


}    
    
    
    
 /*   public function update_party($id, $datas) {
        $this->db->where('id', (int)$id);
        $this->db->update('parties', $datas);
        return (int)$id;
    }*/

function modify_party($party_id, $name_event, $content)
	{
		
		$this->db->set('name_event', $name_event);
		$this->db->set('content', $content);
		
                
		$this->db->where('id', $party_id);

		$this->db->update($this->table_name);
		return $this->db->affected_rows() > 0;
	}



/*    public function delete_party($id) {
        $this->db->delete('parties', array('id' => (int)$id));
    } */

function delete_party($party_id)
	{
		$this->db->where('id', $party_id);
		$this->db->delete($this->table_name);
		
	}

}
